package chase.myrewards;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.text.util.Linkify;
import android.util.Log;
import android.graphics.Color;
import android.widget.TextView;

/**
 * A specialized extension of an Android Dialog that uses a layout xml
 * file to specify its contents.
 * 
 * @author Meena Abdou
 * @date 05/11/2013
 */
public class AboutDialog extends Dialog {

	private static Context mContext = null;

	public AboutDialog(Context context) {
		super(context);
		mContext = context;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.about);
		TextView tv = (TextView)findViewById(R.id.info_text);
		tv.setText(Html.fromHtml(readRawTextFile("about.html")));
		tv.setLinkTextColor(Color.WHITE);
		Linkify.addLinks(tv, Linkify.ALL);
	}
	
	public static String readRawTextFile(String url) {
		try {
			InputStream inputStream = mContext.getAssets().open(url);
			InputStreamReader in = new InputStreamReader(inputStream);
			BufferedReader buf = new BufferedReader(in);
			String line;
			StringBuilder text = new StringBuilder();
			while (( line = buf.readLine()) != null){
				text.append(line);
			}
			Log.d("", text.toString());
			return text.toString();
		} 
		catch (IOException e) {
			Log.e("AboutDialog", "IOException", e);
			return null;
		}
	}
}
